﻿define([
    'require',
    'angular',
    'underscore'
], function (require, angular, _) {
    return function ($scope, Resource,RuleSerivce, $dataSourceManager, GillionMsg, $location,$compile, $timeout, $routeParams,$http,$rootScope,RuleEditService) {
        $scope.testId = $location.search().testId;
        RuleSerivce.readyData();
        RuleSerivce.setVariableScope(3);

        //加载上次测试执行记录
        $scope.executeRow=[];
        $scope.executeRule=[];
        if($scope.testId) {
            Resource("/grule-manager/test-log/rule/:id", {id: '@id'}).get({
                id: $routeParams.ruleId,
                testId:$scope.testId
            }, function (response) {
                if (response.data != null) {
                    $scope.executeRow = response.data;
                }
            });
        }

        $rootScope.headerPackageId=$routeParams.packageId;

        RuleSerivce.promises().then(function () {
            if($scope.testId) {
                $http({
                    method: 'GET',
                    url: '/grule-manager/test-log/package',
                    params: {
                        testId: $scope.testId
                    }
                }).success(function (resp) {
                    if (resp.data != null) {
                        $scope.executeRule = resp.data;
                    }
                });
            }
            $scope.status=$rootScope.currPackage.status;
            $scope.businessModelId=$scope.currPackage.businessModelId;
            //加载模型
            Resource("/grule-manager/businessModelAttribute/list/:id", {id: '@id'}).get({
                id:  $scope.businessModelId
            }, function (response) {
                if(response.data!=null){
                    $scope.modelAttributes=response.data;
                }
            });

            Resource("/grule-manager/data_dict/rule/dict/:id",{id: '@id'}).get({ id:  $rootScope.currProjcet.id}, function (response) {
                if(response.data!=null){
                    $scope.dicts=response.data;
                }
            });

            Resource("/grule-manager/templet").get(function (response) {
                if(response.data!=null){
                    $scope.templets =response.data;
                }
            });
            var response = $rootScope.currRule;
            $scope.ruleName=response.name;
            $scope.context = response.expression;
            if($scope.context!=null&&$scope.context!="undefined"&&$scope.context!="{}"){
                var json = eval('(' + $scope.context + ')');
                var conditionList=RuleEditService.showRule(json.if.condition);
                RuleEditService.setHtml($scope,conditionList,'condition');
                var thenList =RuleEditService.showThen(json.if.then);
                RuleEditService.setHtml($scope,thenList,'then');
            }else{
                RuleEditService.addConditionRow($scope,"","",true);
                RuleEditService.addThen($scope,"setRtnValue","",true);
            }

            if (document.cookie.match(/scrollTop=([^;]+)(;|$)/) != null) {
                var arr = document.cookie.match(/scrollTop=([^;]+)(;|$)/); //cookies中不为空，则读取滚动条位置
                //document.documentElement.scrollTop = parseInt(arr[1]);
                document.getElementById("ruleMes").scrollTop = parseInt(arr[1]);
            }




        });



        $scope.copyRule=function(rule){
            console.log($routeParams.packageId);
            var params = {};
            params.projectId=$routeParams.projectId;
            params.packageId =$routeParams.packageId;
            params.assemblyId = rule.ruleAssemblyId;
            params.ruleId = rule.id;
            GillionMsg.showUrl({
                title: '复制规则',
                url: '/html2/rule/create/copyRule',
                width: 400,
                height:350,
                data: params,
                onClose: function (data) {
                    if (data.success) {
                        RuleSerivce.getRulePackageMenu($scope.packageId);
                    }
                }
            });
        };


        angular.element(document).trigger('refresh.menu');
        angular.element(document).on('refresh.rule', function(){
            RuleSerivce.getRulePackageMenu($scope.packageId);
            ruleResource.get({"id":$scope.id},function(response){
                $scope.ruleName=response.name;
            })
        });

        angular.element('.engine-tab li:first').trigger('click');
        $scope.id=$routeParams.ruleId;
        $scope.packageId = $routeParams.packageId;
        $scope.projectId = $routeParams.projectId;
        RuleSerivce.getRulePackageMenu($routeParams.packageId);
        Resource("/grule-manager/projects/"+$scope.projectId).get({},function(project){
            $scope.currProjcet = project;
        });

        $scope.count=1;
        $scope.countCondition=1;
        $scope.nowClick = 1;
        $scope.jsonContext={};
        $scope.showSign=false;
        $scope.showProperty=false;
        $scope.showEntry=false;
        $scope.showNone=true;
        $scope.showAllCondition=false;
        $scope.showMethod=false;

        $scope.conditionRows=[];
        $scope.thenRows=[];
        $scope.conditions=[];

        $scope.selectPackage= function() {
            var url ="#/projects/"+$scope.currProjcet.id+"/packages/"+$scope.currPackage.id+"?testId="+$scope.testId;
            if($scope.isMes){
                GillionMsg.confirm('提示信息', '当前配置未保存，是否离开？',
                    function (r) {
                        if(r){
                            window.location.href=url;
                        }else{
                            return false;
                        }
                    })
            }else {
                window.location.href = url;
            }
        }
        $scope.beforeSelect= function(menu) {
            $scope.saveScroll();
            if($scope.isMes){
                GillionMsg.confirm('提示信息', '当前配置未保存，是否离开？',
                    function (r) {
                        if(r){
                            $scope.select(menu);
                        }else{
                            return false;
                        }
                    })
            }else{
                $scope.select(menu);
            }
        }

        $scope.select = function(menu){
            if(menu.decisionTable){
                RuleSerivce.setCurrentDecisionTable(menu);
                RuleSerivce.setVariableScope(4);
            }
            else{
                RuleSerivce.setCurrentAssembly(menu);
                RuleSerivce.setVariableScope(2);
            }
            var url="";
            if(menu.type==0){
                url="#/projects/"+$scope.currProjcet.id+"/packages/"+$scope.packageId+"/assemblys/"+menu.id+"?testId="+$scope.testId;
            }else if(menu.type==1){
                url="#/projects/"+$scope.currProjcet.id+"/packages/"+$scope.packageId+"/decisionTables/"+menu.id+"?testId="+$scope.testId;
            }else{
                url="#/projects/"+$scope.currProjcet.id+"/packages/"+$scope.packageId+"/decisionTrees/"+menu.id+"?testId="+$scope.testId;
            }
            window.location.href=url;
        };

        $scope.beforeSelectRule= function(rule,menu) {
            $scope.saveScroll();
            if($scope.isMes){
                GillionMsg.confirm('提示信息', '当前配置未保存，是否离开？',
                    function (r) {
                        if(r){
                            $scope.selectRule(rule,menu);
                        }else{
                            return false;
                        }
                    })
            }else{
                $scope.selectRule(rule,menu);
            }
        }

        $scope.saveScroll=function (){
            var scrollPos;
            if (typeof document.getElementById("ruleMes") != 'undefined') {
                scrollPos = document.getElementById("ruleMes").scrollTop;
            }
            document.cookie = "scrollTop=" + scrollPos; //存储滚动条位置到cookies中
        };


        $scope.selectRule = function(rule,menu){
            $http({
                url:"/grule-manager/ruleAssembly/"+rule.ruleAssemblyId,
                method:"GET",
                params:{
                    id:rule.ruleAssemblyId
                }
            }).success(function(resp){
                RuleSerivce.setCurrentAssembly(resp);
            });
            RuleSerivce.setCurrentRule(rule);
            RuleSerivce.setVariableScope(3);
            var url="";
            if(menu.type==0){
                url="#/projects/"+$scope.currProjcet.id+"/packages/"+$scope.packageId+"/assemblys/"+menu.id+"/rules/"+rule.id+"?testId="+$scope.testId;
            }else if(menu.type==1){
                url="#/projects/"+$scope.currProjcet.id+"/packages/"+$scope.packageId+"/decisionTables/"+menu.id+"/rules/"+rule.id+"?testId="+$scope.testId;
            }else{
                url="#/projects/"+$scope.currProjcet.id+"/packages/"+$scope.packageId+"/decisionTrees/"+menu.id+"/rules/"+rule.id+"?testId="+$scope.testId;
            }
            window.location.href=url;
        };

        var childAttributeResource = Resource("/grule-manager/businessModelAttribute/childList/:id", {
            id: "@id"
        });
        var ruleResource = Resource("/grule-manager/rule/:id", {
            id: "@id"
        });

        //加载变量
        function loadVariables() {
            Resource("/grule-manager/variables/rule/:id", {id: '@id'}).get({
                id:  $scope.id
            }, function (response) {
                if(response.data!=null){
                    $scope.variables=response.data;
                }
            });
        }
        loadVariables();

        angular.element(document).off('refresh.variables').on('refresh.variables', function() {
            loadVariables();
        });

        $scope.change=function (click){
            RuleEditService.change($scope,click);
        };

        $scope.selectLogicalSign=function(sign,mes,num){
            $scope.count++;
            var node   = angular.element("#symbol" + num).parent().empty();
            node.append(
                $compile(
                    "<a href='javascript:void(0)' ng-click='change("+$scope.count+")' name='node'  id='symbol"+$scope.count+"' value='{&apos;oper&apos;:&apos;"+sign+"&apos;}'>"+mes+"<i class='icon-engine-down-a'></i></a>"
                )($scope)
            )
        };
        $scope.changeThen=function(click){
            var height1 = document.getElementById('rule-edit').scrollHeight;
            RuleEditService.changeThen($scope,click);
            var height2 = document.getElementById('rule-edit').scrollHeight;
            if(height1<height2){
                document.getElementById('rule-edit').scrollTop=document.getElementById('rule-edit').scrollHeight;
            }

        };

        $scope.selectResultType=function(sign,mes,num,type){
            $scope.count++;
            var node   = angular.element("#then" + num).parent().empty();
            node.append(
                $compile(
                    "<a href='javascript:void(0)' ng-click='changeThen("+$scope.count+")' name='node'  id='then"+$scope.count+"' type='"+type+"' value='{&apos;type&apos;:&apos;"+sign+"&apos;}'>"+mes+"<i class='icon-engine-down-a'></i></a>"
                )($scope)
            )
        };
        $scope.removeCondition = function(num){
            angular.element("#click" + num).remove();
        };

        $scope.removeRowCondition=function(index){
            $scope.conditionRows.splice(index, 1);
        };
        $scope.copyCRow=function(index){
            RuleEditService.copyCRow($scope,index);
        };

        $scope.copyTRow=function(index){
            RuleEditService.copyTRow($scope,index);
        };

        $scope.addRowCondition=function(index){
            RuleEditService.addRowCondition($scope,index);
        };
        $scope.removeRowThen=function(index){
            $scope.thenRows.splice(index, 1);
        };

        $scope.addThen=function(type,thenList,isButton){
            RuleEditService.addThen($scope,type,thenList,isButton);
        };
        $scope.addConditionRow=function(type,conditionList,isButton){
            RuleEditService.addConditionRow($scope,type,conditionList,isButton);
        };
        $scope.addRowThen=function(index){
            RuleEditService.addRowThen($scope,index);
        };
        $scope.upThen=function(index){
            RuleEditService.upThen($scope,index);
        };
        $scope.downThen=function(index){
            RuleEditService.downThen($scope,index);
        };
        $scope.upCondition=function(index){
            RuleEditService.upCondition($scope,index);
        };
        $scope.downCondition=function(index){
            RuleEditService.downCondition($scope,index);
        };

        $scope.show=function(type,model,showType){
            RuleEditService.show($scope,type,model,showType);
        };
        $scope.viewObject = function (id,margin) {
            RuleEditService.viewObject($scope,id,margin)
        };
        $scope.addButton= function(){
            RuleEditService.addButton($scope);
        };
        $scope.addEntry=function(){
            RuleEditService.addEntry($scope);
        };
        $scope.addDict=function(item){
            RuleEditService.addDict($scope,item);
        };
        $scope.addSign=function(value){
            RuleEditService.addSign($scope,value);
        };
        $scope.addModel=function(value){
            RuleEditService.addModel($scope,value);
        };

        $scope.addVariable=function(value){
            RuleEditService.addVariable($scope,value);
        };

        $scope.addMethod=function(value,text){
            RuleEditService.addMethod($scope,value,text);
        };


        $scope.addFront=function(value){
            RuleEditService.addFront($scope,value);
        };

        $scope.addBehind=function(value){
            RuleEditService.addBehind($scope,value);
        };

        $scope.save=function(){
            $scope.isMes=false;
            var list=[];
            var nodes = $("a[name='node']");
            angular.forEach(nodes,function(node){
                list.push( eval("(" + node.attributes.value.nodeValue + ")"));
            });
            var conditionList = [];
            var resultList=[];
            for(var i=0;i<list.length;i++){
                if(list[i].type=="execute"||list[i].type=="throw"||list[i].type=="setVariable"||list[i].type=="setRtnValue"||list[i].type=="breakPackage"||list[i].type=="breakAssembly"||list[i].type=="setModel"){
                    conditionList = list.slice(0,i);
                    resultList = list.slice(i,list.length);
                    break;
                }
            }
            if(resultList.length==0){
                GillionMsg.alert("提示","请编辑规则返回信息！");
                return;
            }
            if(conditionList.length==0){
                GillionMsg.alert("提示","请编辑规则条件！");
                return;
            }
            var flag  = checkBrackets(conditionList);
            if(!flag){
                return;
            }
            var flag  = checkBrackets(resultList);
            if(!flag){
                return;
            }
            var condition = RuleEditService.getCondition(conditionList);//条件
            var result = RuleEditService.getResult(resultList);
            var rule={};
            var expression ={"if":{"condition":{},"then":[]}};
            expression.if.condition = condition;
            expression.if.then=result;
            rule.id= $scope.id;
            rule.expression= JSON.stringify(expression);
            if(rule.expression==null||rule.expression==undefined){
                rule.expression="{}";
            }

            flag  = checkRule(expression);
            if(flag==false){
                return;
            }
            ruleResource.update(rule, function (response) {
                if(response.success){
                    GillionMsg.alert("提示","修改成功！");
                }else{
                    GillionMsg.alert("提示","修改失败！");
                }
            });
        };

        $scope.deleteAssembly=function(id){
            GillionMsg.confirm('提示信息', '是否确定删除？',
                function (r) {
                    if(r==true) {
                        Resource("/grule-manager/ruleAssembly/:id", {
                            id: "@id"
                        }).delete({
                            id: id
                        }, function (response) {
                            if (response.success) {
                                GillionMsg.alert('提示', '删除成功', function(){
                                    angular.element(document).trigger('refresh.menu');
                                    window.location.href='/html2/home#/projects/' + $scope.projectId + '/packages/' +  $scope.packageId;
                                });
                            }
                        });
                    }
                }
            );
        };

        $scope.deleteRule=function(id){
            GillionMsg.confirm('提示信息', '是否确定删除？',
                function (r) {
                    if (r == true) {
                        Resource("/grule-manager/rule/:id", {
                            id: "@id"
                        }).delete({
                            id: id
                        }, function (response) {
                            if(response.success){
                                GillionMsg.alert('提示', '删除成功', function(){
                                    angular.element(document).trigger('refresh.menu');
                                    window.location.href='/html2/home#/projects/' + $scope.projectId + '/packages/' +  $scope.packageId;
                                });
                            }
                        });
                    }
                }
            )
        };
        function checkBrackets(list){
            var left=0;
            var right =0;
            for(var i=0;i<list.length;i++){
                if(list[i].oper=="("){
                    left++;
                }
                if(list[i].oper==")"){
                    right++;
                }
            }
            if(left!=right){
                GillionMsg.alert('提示', '括号为配对，请确认！');
                return false;
            }
            return true;
        }


        function checkRule(expression){
            if(expression=="{}"){
                return;
            }else{
                if(expression.if==undefined||expression.if.condition==undefined||expression.if.then==undefined){
                    GillionMsg.alert('提示', '如果那么条件出错，请确认！');
                    return false;
                }else {
                    var condition = expression.if.condition;
                    var then = expression.if.then;
                    var flag = checkRuleForRec(condition);
                    if(flag==false) {
                        return flag;
                    }else{
                        for(var i=0;i<then.length;i++){
                           flag = checkRuleForRec(then[i]);
                            if(flag==false){
                                return flag;
                            }
                        }
                    }
                }
            }
        }

        function checkRuleForRec(expression){
            if (expression.oper != undefined ) {
                if(expression.left == undefined || expression.right == undefined){
                    GillionMsg.alert('提示', '条件部分不满足，请仔细查看！');
                    return false;
                }else{
                    var flag = checkRuleForRec(expression.left);
                    if(flag) {
                        return checkRuleForRec(expression.right);
                    }else{
                        return false;
                    }
                }
            }
            if(expression.type=="parenthesis"){
                return checkRuleForRec(expression.expression);
            }
            if(expression.type=="matcher"||expression.type=="matchWith"||expression.type=="startWith"||expression.type=="endsWith"){
                if(expression.source==null||expression.str==null){
                    GillionMsg.alert('提示', '字符串操作方法错误，请仔细查看！');
                    return false;
                }else{
                    return checkRuleForRec(expression.source);
                }
            }
            if(expression.type=="setVariable"){
                if(expression.key==null||expression.value==null){
                    GillionMsg.alert('提示', '变量赋值操作错误，请仔细查看！');
                    return false;
                }else{
                    return checkRuleForRec(expression.value);
                }
            }
            if(expression.type=="setModel"){
                if(expression.modelId==null||expression.modelValue==null){
                    GillionMsg.alert('提示', '属性赋值操作错误，请仔细查看！');
                    return false;
                }else{
                    return checkRuleForRec(expression.modelValue);
                }
            }
            if(expression.type=="execute"){
                if(expression.code==undefined&&expression.value==undefined){
                    GillionMsg.alert('提示', '执行操作错误，请仔细查看！');
                    return false;
                }else {
                    if(expression.value!=undefined){
                        return checkRuleForRec(expression.value);
                    }
                }
            }
            if(expression.type=="MapGet"){
                if(expression.map==undefined||expression.key==undefined){
                    GillionMsg.alert('提示', 'MAP获取配置错误，请仔细查看！');
                    return false;
                }
            }
            if(expression.type=="MapPut"){
                if(expression.map==undefined||expression.key==undefined||expression.value==undefined){
                    GillionMsg.alert('提示', 'MAP设置配置错误，请仔细查看！');
                    return false;
                }
            }
            if(expression.type=="ListAdd"&&(expression.list==undefined||expression.value==undefined)){
                    GillionMsg.alert('提示', 'List添加配置错误，请仔细查看！');
                    return false;
            }
            if(expression.type=="clearList"&&expression.value==undefined){
                GillionMsg.alert('提示', 'List清空配置错误，请仔细查看！');
                return false;
            }
            if(expression.type=="clearMap"&&expression.value==undefined){
                GillionMsg.alert('提示', 'Map清空配置错误，请仔细查看！');
                return false;
            }
            if(expression.type=="JDBCService"&&(expression.sqlName==undefined)){
                GillionMsg.alert('提示', 'JDBC组件配置错误，请仔细查看！');
                return false;
            }
            if(expression.type=="Dubbo"&&(expression.dubboName==undefined)){
                GillionMsg.alert('提示', 'dubbo组件配置错误，请仔细查看！');
                return false;
            }
            if(expression.type=="Rule"&&(expression.groupId==undefined||expression.artifactId==undefined)){
                GillionMsg.alert('提示', '规则组件配置错误，请仔细查看！');
                return false;
            }
            if(expression.type=="setRtnValue"&&expression.value==undefined){
                GillionMsg.alert('提示', '请配置返回值！');
                return false;
            }
            return true;
        }


        //type  按钮或者节点   state 编辑状态还是保存后状态，由于传入的节点不同，进行判断
        window.showEdit=function(type){
            RuleEditService.showEdit($scope,type);
        };
        //type  按钮或者节点   state 编辑状态还是保存后状态，由于传入的节点不同，进行判断
        window.closeEdit=function(type,state){
            RuleEditService.closeEdit(type,state);
        };
        //添加括号方法
        $scope.addBracket=function(num){
            var nodesList=[];
            //$("#bracket").css("display", "block");
            var  rowNodes =$("[name='rowC']");
            for(var i=0;i<rowNodes.length;i++){
                var divNodes = rowNodes[i].children;// <div>
                var spanNodes = divNodes[1].children; //<span>
                for(var j=0;j<spanNodes.length;j++){
                    var aNode = spanNodes[j].children;
                    nodesList.push(aNode[0]);
                }
            }
            for(var i=0;i<nodesList.length;i++){
                if(nodesList[i].attributes.type!=undefined) {
                    if (nodesList[i].attributes.type.nodeValue == "property" || nodesList[i].attributes.type.nodeValue == "variable" || nodesList[i].attributes.type.nodeValue == "entry") {
                        //nodesList[i].addClass("attribute-kuoh-c");
                        var node = angular.element("#" + nodesList[i].id);
                        node.parent().addClass("attribute-kuoh");
                        node.after(
                            $compile(
                                "<div class='left' name ='leftBracket'><a href='javascript:void(0)' ng-click='addLeftBracket(&apos;" + nodesList[i].id + "&apos;)'>(</a></div>"
                            )($scope)
                        )
                    }
                }
            }
            showLeftBracket();
        };

        //点击左括号之后显示右括号
        function showRightBracket(nodeId){
            var nodesList=[];
            var startList=[];
            var  rowNodes= $("[name='rowC']");
            for(var i=0;i<rowNodes.length;i++){
                var divNodes = rowNodes[i].children;// <div>
                var spanNodes = divNodes[1].children; //<span>
                for(var j=0;j<spanNodes.length;j++){
                    var aNode = spanNodes[j].children;
                    nodesList.push(aNode[0]);
                }
            }
            for(var i=0;i<nodesList.length;i++){
                if(nodesList[i].id==nodeId){
                    startList=nodesList.slice(i,nodesList.length);
                    break;
                }
            }
            for(var i=0;i<startList.length;i++){
                if(nodesList[i].attributes.type!=undefined) {
                    if (startList[i].attributes.type!=undefined&&(startList[i].attributes.type.nodeValue == "property" || startList[i].attributes.type.nodeValue == "variable" || startList[i].attributes.type.nodeValue == "entry")) {
                        //nodesList[i].addClass("attribute-kuoh-c");
                        var node = angular.element("#" + startList[i].id);
                        node.parent().addClass("attribute-kuoh");
                        node.after(
                            $compile(
                                "<div class='right' name ='rightBracket'><a href='javascript:void(0)' ng-click='addRightBracket(&apos;" + startList[i].id + "&apos;)'>)</a></div>"
                            )($scope)
                        )
                    }
                }
            }
        }




        //添加左括号
        $scope.addLeftBracket= function(nodeId){
            $scope.countCondition++;
            var node =angular.element("#" + nodeId) ;
            var span = node.parent();
            span.before(
                $compile(
                    "<span  id='click" + $scope.countCondition + "'  onmouseleave='closeEdit(&apos;node&apos;)'  onmouseenter='showEdit(&apos;node&apos;)'  ><a href='javascript:void(0)' name='node'  id='node"+$scope.countCondition+"'  ng-click='show(&apos;"+$scope.countCondition+"&apos;,&apos;node&apos;,&apos;sign&apos;)'  type='sign' value='{&apos;oper&apos;:&apos;(&apos;}'>(</a></span>"
                )($scope)
            );

            cleanBracket("left");
            showRightBracket(nodeId);
        };

        //添加右边括号
        $scope.addRightBracket= function(nodeId){
            $scope.countCondition++;
            var node =angular.element("#" + nodeId) ;
            var span = node.parent();
            span.after(
                $compile(
                    "<span  id='click" + $scope.countCondition + "'  onmouseleave='closeEdit(&apos;node&apos;)'  onmouseenter='showEdit(&apos;node&apos;)'  ><a href='javascript:void(0)' name='node'  id='node"+$scope.countCondition+"'  ng-click='show(&apos;"+$scope.countCondition+"&apos;,&apos;node&apos;,&apos;sign&apos;)'  type='sign' value='{&apos;oper&apos;:&apos;)&apos;}'>)</a></span>"
                )($scope)
            );

            cleanBracket("right");
            $("#shadeCondition").css({ display: "none"});
        };

        function showLeftBracket(){
            $("#shadeCondition").css({ display: "block"});
            $("#bracket").css("display", "block");
        }

        //type: left | right | all
        function cleanBracket(type){
            if(type=="left"||type=="all"){
                var  bracketNodes= $("[name='leftBracket']");
                for(var i=0;i<bracketNodes.length;i++){
                    bracketNodes[i].remove();
                }
            }
            if(type=="right"||type=="all"){
                var  bracketNodes= $("[name='rightBracket']");
                for(var i=0;i<bracketNodes.length;i++){
                    bracketNodes[i].remove();
                }
            }
        }

        //点击遮罩还原
        $("#shadeCondition").mouseup(function(){
            $("#shadeCondition").css({ display: "none"});
            //cleanBracket("all");
            angular.element("#node" + $scope.nowClick).removeClass("attribute-check");
            angular.element("#showCondition" + $scope.nowClick).removeClass("attribute-check");
            angular.element("#showCondition" + $scope.nowClick).html("点击选择");
            RuleEditService.init($scope);
        });

        $scope.isExecuteRule=function(id){
            if($scope.executeRule.indexOf(id)>-1){
                return true;
            }else{
                return false;
            }
        }

        $scope.isExecuteRow=function(index){
            if($scope.executeRow.indexOf(index+1)>-1){
                return true;
            }else{
                return false;
            }
        }
    }
})

